perm filename TIMES.MID[NET,MRC]3 blob sn#352672 filedate 1978-05-03 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00006 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	TITLE TIMES
C00003 00003	GO LUP LUPNXT NTMTAB
C00006 00004	NETIM TIME CONBLK CONSTS CONLSK CONHST
C00008 00005	TIMCAS TIMCA2 TIMCA3 TMONTB
C00012 00006	TIMOUT DEC2OU DECOUT
C00014 ENDMK
C⊗;
TITLE TIMES

; Time Sites
; Hack courtesy of KLH
; Hacked for SAIL by MRC

GMTDIF==8.

A=1
B=2
C=3
D=4
E=5
N=10
N1=11
P=17

PDLLEN==20
PDL:	BLOCK PDLLEN
	0
;GO LUP LUPNXT NTMTAB

GO:	JFCL
	RESET
	MSTIME
	MOVEM TSTART'
	MOVEI 261
	PEEK
	PEEK
	MOVEM DAYLIT'
	MOVE P,[-PDLLEN,,PDL]
	OUTSTR [ASCIZ/ Site	Greenwich Mean Time	Local Time
/]
	; Now loop thru sites in table...
	MOVSI C,-NTHSTS
LUP:	HRRZ A,NTMTAB(C)
	OUTSTR (A)		; Type site name.
	HLRZ A,NTMTAB(C)	; Get site # to hack, and
	PUSHJ P,NETIM		; Get net time for foreign site.
	 JRST [	OUTSTR [ASCIZ/'s time is unavailable.
/]
		JRST LUPNXT]

	; Here, have net time in A.  Print out...
	MOVE B,A		; save
	PUSHJ P,TIMCAS		; Convert one as GMT,
	EXCH A,B		; get saved value,
	SUBI A,GMTDIF*3600.	; and use to get local-time value,
	SKIPE DAYLIT
	 ADDI A,3600.		; daylight losing time
	PUSHJ P,TIMCAS		; converted thereto.
	OUTSTR [ASCIZ/	/]
	MOVE D,B
	PUSHJ P,TIMOUT
	OUTSTR [ASCIZ/  ->  /]
	MOVE D,A
	PUSHJ P,TIMOUT
	SKIPE DAYLIT
	 JRST [	OUTSTR [ASCIZ/ PDT.
/]
		JRST LUPNXT]
	OUTSTR [ASCIZ/ PST.
/]
LUPNXT:	AOBJN C,LUP
	MSTIME A,			; Get sys time at end.
	SUB A,TSTART			; Find total 1000'ths we ran in real time.
	IDIVI A,1000.			; # secs in A, rem in B
	IDIVI B,10.			; Get 2 digits after decimal pt.
	OUTSTR [ASCIZ/Realtime used: /]
	MOVEI N,(A)
	PUSHJ P,DECOUT
	OUTCHR [".]
	MOVEI N,(B)
	PUSHJ P,DECOUT
	OUTSTR [ASCIZ/ secs
/]
	EXIT

NTMTAB:	20,,[ASCIZ /AMES-67/]
	206,,[ASCIZ /MIT-AI/]
	306,,[ASCIZ /MIT-ML/]
	106,,[ASCIZ /MIT-DM/]
	354,,[ASCIZ /MIT-MC/]
	13,,[ASCIZ /SU-AI/]
NTHSTS==.-NTMTAB
;NETIM TIME CONBLK CONSTS CONLSK CONHST

; NETIM - Hack to pluck 32-bit Network-time word from site
;	specified by A.  Returns value in A and skips,
;	doesn't skip if couldn't get.

NETIM:	MOVEM A,CONHST
	INIT 17				; open in dump mode
	 'IMP,,				; device IMP:
	 0				; no buffers
	 JRST 4,.
	MTAPE [17 ? .BYTE 6 ?1?0?0?5?5?0]; set timeouts
	SETOM CONLSK			; gensym socket to use
	MTAPE CONBLK			; connect → foreign logger
	MOVE CONSTS			; check for MTAPE error
	TRNE 77
	 POPJ P,
	STATZ 763600
	 POPJ P,
	TLC 300000			; for next instruction to win
	TLCE 300000			; legal socket state?
	 POPJ P,
	HRROI A,TIME-1			; get ready to get a socket
	SETZ B,				; stop code for dump mode
	IN A				; get socket from logger
	 AOS (P)			; won
	LDB A,[044000,,TIME]
	RELEASE
	POPJ P,

TIME:	BLOCK 1				; time

CONBLK:	0				; CONNECT
CONSTS:	BLOCK 1				; returned status bits
CONLSK:	BLOCK 1				; local socket
	-1				; ≠ 0 → wait for connection until timeout
	BLOCK 1				; byte size
	45				; foreign socket
CONHST:	BLOCK 1				; foreign host
;TIMCAS TIMCA2 TIMCA3 TMONTB

; TIMCAS - Converts Absolute Seconds to time word.
;	Argument in A (# secs since 1/1/00), returns time wd in A.

TIMCAS:	PUSH P,B
	PUSH P,C
	IDIVI A,24.*60.*60.	; Get remainder of # secs in day
	PUSH P,B
	IDIVI A,365.		;find # "normal" years.
	JUMPE A,TIMCA2		; Avoid 1900 lossage.
	MOVEI C,-1(A)		;now see how many leap years covered (not incl current)
	LSH C,-2		;divide by 4 to get # leap yrs
	SUBI B,(C)		;adjust cnt of remaining days
	JUMPGE B,TIMCA2
	SUBI A,1		;backed past year boundary? bump down # yrs
	ADDI B,365.		;if negative, must adjust again
	TRNN A,3		;if in leap year,
	 ADDI B,1		;add one more since 366. days in LY
TIMCA2:	MOVEI C,12.
	CAMGE B,TMONTB(C)	;compare # days in year with # days after each month
	 SOJG C,.-1		;loop (#1 index has 0 value, so it will stop)
	TRNE A,3		;leap year?
	 CAIGE C,3		;ugh, yes. but if in jan or feb,
	  JRST TIMCA3		;saved.  else it's after feb and must hack it.
	SUBI B,1		;lower value
	CAMGE B,TMONTB(C) 	;still wins?
	 SUBI C,1		;if not, bump month down.
	CAIN C,2		;if now in Feb,
	 AOJA B,.+1		;restore value so subtracting TMONTB gives 29, not 28.
TIMCA3:	SUB B,TMONTB(C)		;get # of day within month
	DPB A,[TM$YR,,A]	;deposit year
	DPB C,[TM$MON,,A]	;and month
	MOVEI B,1(B)		; First day of month is day 1, not day 0.
	DPB B,[TM$DAY,,A]	;and day.
	ANDCMI A,-1		;Zap RH to start of day.
	POP P,B
	LSH B,1
	ADDI A,(B)		; Add in # half secs.
	POP P,C
	POP P,B
	POPJ P,

; Mask    Field     Bits	Range	Var.    Variable range

TM%SEC== 777776    ; 2.9-1.2	0-131K	seconds	0-86399.
TM%DAY==     37,,0 ; 3.5-3.1	0-31	days	1-31
TM%MON==    740,,0 ; 3.9-3.6	0-15	months	1-12
TM%YR==  177000,,0 ; 4.7-4.1	0-127	years	0-127 relative to 1900 (1900-2027)
TM$SEC==(.BP TM%SEC,)	; Define BP LH's into each field.
TM$DAY==(.BP TM%DAY,)
TM$MON==(.BP TM%MON,)
TM$YR== (.BP TM%YR,)

	; Special table to allow figuring how many days so far
	; in this year.  Indexed by month # (1-12) gives # days
	; taken up by months preceding it.  Assumes non-leap year.
TMONTB:	0
	0
	31.	;+jan
	59.	;+jan+feb
	90.	;+jan+feb+mar...
	120.	;...+apr
	151.	;...+may
	181.	;...+jun
	212.	;...+jul
	243.	;...+aug
	273.	;...+sep
	304.	;...+oct
	334.	;...+nov
;TIMOUT DEC2OU DECOUT

; TIMOUT - Output date/time in D

TIMOUT:	LDB N,[TM$MON,,D]
	PUSHJ P,DEC2OU
	OUTCHR ["/]
	LDB N,[TM$DAY,,D]
	PUSHJ P,DEC2OU
	OUTCHR ["/]
	LDB N,[TM$YR,,D]
	PUSHJ P,DEC2OU
	OUTCHR [" ]
	LDB N,[TM$SEC,,D]
	IDIVI N,60.*60.
	PUSH P,N1
	PUSHJ P,DEC2OU
	OUTCHR [":]
	POP P,N
	IDIVI N,60.
	PUSH P,N1
	PUSHJ P,DEC2OU
	OUTCHR [":]
	POP P,N
;	JRST DEC2OU

; DEC2OU - Output two-digit decimal number in N

DEC2OU:	IDIVI N,10.
	ADDI N,"0
	OUTCHR N
	ADDI N1,"0
	OUTCHR N1
	POPJ P,

; DECOUT - Output decimal number in N

DECOUT:	IDIVI N,10.
	PUSH P,N1
	SKIPE N
	 PUSHJ P,DECOUT
	POP P,N
	ADDI N,"0
	OUTCHR N
	POPJ P,

END GO